<?php


namespace Admin\Model;
use Think\Model;

class GoodsbrandModel extends Model {

//添加品牌
    public function toadd($data = null){

        $data = $this->create($data);
//        dump($data);
        if(empty($data)){
            return false;
        }

        $z = $this->add();

        return $z;
    }
//修改品牌
    public function upd($data = null){

        $data = $this->create($data);
        if(empty($data)){
            return false;
        }
        $z = $this->save();
//        dump($z);
        return $z;
    }
//获取品牌列表支持分页
//获取一级品牌列表支持分页
    public function lists($category, $order = '`id` DESC', $status = 1, $field = true, $limit = '10', $map = array()){
        $map = array_merge($this->listMap($category, $status), $map);
        return $this->field($field)->where($map)->order($order)->limit($limit)->select();
    }


//批量修改推荐
    public function rec($id,$recommend){

        if(is_array($id)){
            if (empty($id)) {
                return false;
            }
            $id = array_unique((array)$id);
//            $id = is_array($id) ? implode(',', $id) : $id;
            $map = array('id' => array('in', $id) );

            $z = $this->where($map)->setField('recommend',$recommend);
        }else{
            if($recommend){
                $z = $this->where("id = $id")->setField('recommend','0');
            }else{
                $z = $this->where("id = $id")->setField('recommend','1');
            }
        }

        return $z;

    }

//删除制定分类或批量删除
    public function del($id = null){
//dump($id);
        if (empty($id)) {
            return false;
        }

        $id = array_unique((array)$id);
//            $id = is_array($id) ? implode(',', $id) : $id;
        $map = array('id' => array('in', $id) );

        $z = $this->where($map)->setField('state','-1');

        if ($z) {
            return true;
//            $this->success('删除成功', U('index'));
        } else {
            return false;
//            $this->success('删除失败', U('index'));
        }
    }



}
